import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/user/:id",
    name: "User",
    component: () => import("../views/User.vue"),
    children: [
      // 当 /user/:id 匹配成功，
      // UserHome 会被渲染在 User 的 <router-view> 中
      // {
      //   path: '',
      //   component: () => import("../views/UserHome.vue")
      // },
      {
        // 当 /user/:id/profile 匹配成功，
        // UserProfile 会被渲染在 User 的 <router-view> 中
        path: "profile",
        component: () => import("../views/UserProfile.vue"),
      },
      {
        // 当 /user/:id/posts 匹配成功
        // UserPosts 会被渲染在 User 的 <router-view> 中
        path: "/posts",
        component: () => import("../views/UserPosts.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});

export default router;
